using MediatR;
using RBAC.Domain.WarehouseManagement;
using RBAC.ErrorCode;
using RBAC.Interstructrue.Base;
using RBAC.Read.Api.Application.Command.ERP.PurchasingManagement.PurchaseInvoicefolder;
using Dapper;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System;
namespace RBAC.Read.Api.Application.Handler.ERP.PurchasingManagement.PurchaseInvoicefolder
{
    public class PrintSalesReturnDetailCommandHandler : IRequestHandler<PrintSalesReturnDetailCommands, APIResult<List<SalesReturnDetails>>>
    {
        private readonly IBaseRepository<SalesReturnDetails> _repo;

        public PrintSalesReturnDetailCommandHandler(IBaseRepository<SalesReturnDetails> repo)
        {
            _repo = repo;
        }

        public Task<APIResult<List<SalesReturnDetails>>> Handle(PrintSalesReturnDetailCommands request, CancellationToken cancellationToken)
        {
            try
            {
                // 打印：不分页，返回全部未删除数据
                var data = _repo.GetAll();

                return Task.FromResult(new APIResult<List<SalesReturnDetails>>
                {
                    Code = APIEnums.Success,
                    Msg = "查询成功",
                    Data = data ?? new List<SalesReturnDetails>()
                });
            }
            catch (Exception ex)
            {
                return Task.FromResult(new APIResult<List<SalesReturnDetails>>
                {
                    Code = APIEnums.Fail,
                    Msg = "查询失败：" + ex.Message,
                    Data = new List<SalesReturnDetails>()
                });
            }
        }
    }
}
